#include <iostream>
using namespace std;

int n;
int month_28[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

int main()
{
    cin >> n;
    int year, month, day;
    while (n--)
    {
        scanf("%d%d%d", &year, &month, &day);
        day = day + 1;
        if (day > month_28[month - 1])
        {
            day = 1;
            month += 1;
            if (month > 12)
            {
                year += 1;
                month = 1;
            }
        }
        printf("%04d-%02d-%02d\n", year, month, day);
    }
    return 0;
}